public class code2_1 {
    //方法二：n&=(n-1)
    public int[] countBits(int n) {
        int[] arr = new int[n+1];
        for(int i=0;i<=n;i++) {
            //判断i有多少个1
            arr[i] = count(i);
        }
        return arr;
    }
    public int count(int n) {
        int ret = 0;
        while(n!=0) {
            n &= (n-1);
            ret++;
        }
        return ret;
    }
}
